package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.product.mapper.BaseCategory1Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory2Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory3Mapper;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XIN
 * 2023/4/16
 */
@Service
@SuppressWarnings("all")
public class BaseCategoryServiceImpl implements BaseCategoryService {
	@Autowired
	private BaseCategory1Mapper baseCategory1Mapper;
	@Autowired
	private BaseCategory2Mapper baseCategory2Mapper;
	@Autowired
	private BaseCategory3Mapper baseCategory3Mapper;
	
	/**
	 * 	查询所有一级分类列表
	 */
	@Override
	public List<BaseCategory1> getCategory1() {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.select("id","name");
		return baseCategory1Mapper.selectList(queryWrapper);
	}
	
	/**
	 * 查询所有er级分类列表
	 * @param category1Id
	 * @return
	 */
	@Override
	public List<BaseCategory2> getCategory2(Long category1Id) {
		LambdaQueryWrapper<BaseCategory2> queryWrapper = new LambdaQueryWrapper();
		queryWrapper.eq(BaseCategory2::getCategory1Id, category1Id);
		queryWrapper.select(BaseCategory2::getId, BaseCategory2::getName);
		List<BaseCategory2> baseCategory2s = baseCategory2Mapper.selectList(queryWrapper);
		return baseCategory2s;
	}
	/***
	 * 查询指定二级分类下三级分类列表
	 * @param category2Id
	 * @return
	 */
	@Override
	public List<BaseCategory3> getCategory3(Long category2Id) {
		LambdaQueryWrapper<BaseCategory3> queryWrapper = new LambdaQueryWrapper();
		queryWrapper.eq(BaseCategory3::getCategory2Id, category2Id);
		queryWrapper.select(BaseCategory3::getId,BaseCategory3::getName);
		return baseCategory3Mapper.selectList(queryWrapper);
	}
}
